package androidx.preference;

import android.content.Context;
import android.content.SharedPreferences;

public class j {

    /* renamed from: a  reason: collision with root package name */
    private Context f829a;

    /* renamed from: b  reason: collision with root package name */
    private long f830b = 0;

    /* renamed from: c  reason: collision with root package name */
    private SharedPreferences f831c;

    /* renamed from: d  reason: collision with root package name */
    private e f832d;
    private SharedPreferences.Editor e;
    private boolean f;
    private String g;
    private int h;
    private int i = 0;
    private PreferenceScreen j;
    private d k;
    private c l;
    private a m;
    private b n;

    public interface a {
        void onDisplayPreferenceDialog(Preference preference);
    }

    public interface b {
        void onNavigateToScreen(PreferenceScreen preferenceScreen);
    }

    public interface c {
        boolean onPreferenceTreeClick(Preference preference);
    }

    public static abstract class d {
        public abstract boolean a(Preference preference, Preference preference2);

        public abstract boolean b(Preference preference, Preference preference2);
    }

    public j(Context context) {
        this.f829a = context;
        q(b(context));
    }

    private static String b(Context context) {
        return context.getPackageName() + "_preferences";
    }

    private void l(boolean z) {
        SharedPreferences.Editor editor;
        if (!z && (editor = this.e) != null) {
            editor.apply();
        }
        this.f = z;
    }

    public <T extends Preference> T a(CharSequence charSequence) {
        PreferenceScreen preferenceScreen = this.j;
        if (preferenceScreen == null) {
            return null;
        }
        return preferenceScreen.H0(charSequence);
    }

    /* access modifiers changed from: package-private */
    public SharedPreferences.Editor c() {
        if (this.f832d != null) {
            return null;
        }
        if (!this.f) {
            return j().edit();
        }
        if (this.e == null) {
            this.e = j().edit();
        }
        return this.e;
    }

    /* access modifiers changed from: package-private */
    public long d() {
        long j2;
        synchronized (this) {
            j2 = this.f830b;
            this.f830b = 1 + j2;
        }
        return j2;
    }

    public b e() {
        return this.n;
    }

    public c f() {
        return this.l;
    }

    public d g() {
        return this.k;
    }

    public e h() {
        return this.f832d;
    }

    public PreferenceScreen i() {
        return this.j;
    }

    public SharedPreferences j() {
        if (h() != null) {
            return null;
        }
        if (this.f831c == null) {
            this.f831c = (this.i != 1 ? this.f829a : b.f.d.a.a(this.f829a)).getSharedPreferences(this.g, this.h);
        }
        return this.f831c;
    }

    public PreferenceScreen k(Context context, int i2, PreferenceScreen preferenceScreen) {
        l(true);
        PreferenceScreen preferenceScreen2 = (PreferenceScreen) new i(context, this).d(i2, preferenceScreen);
        preferenceScreen2.N(this);
        l(false);
        return preferenceScreen2;
    }

    public void m(a aVar) {
        this.m = aVar;
    }

    public void n(b bVar) {
        this.n = bVar;
    }

    public void o(c cVar) {
        this.l = cVar;
    }

    public boolean p(PreferenceScreen preferenceScreen) {
        PreferenceScreen preferenceScreen2 = this.j;
        if (preferenceScreen == preferenceScreen2) {
            return false;
        }
        if (preferenceScreen2 != null) {
            preferenceScreen2.S();
        }
        this.j = preferenceScreen;
        return true;
    }

    public void q(String str) {
        this.g = str;
        this.f831c = null;
    }

    /* access modifiers changed from: package-private */
    public boolean r() {
        return !this.f;
    }

    public void s(Preference preference) {
        a aVar = this.m;
        if (aVar != null) {
            aVar.onDisplayPreferenceDialog(preference);
        }
    }
}
